MetricStringDistance

Metric string distances return a distance metric.

A metric space is a pair \((M, d)\), where \(M\) is a set and \(d\) is a function \(M \times M \to \mathbb{R}\) satisfying the following axioms:

  1. Symmetry Axiom:

    • \(d(x, y) = d(y, x)\)

    • The distance from \(x\) to \(y\) always be the same as the distance from \(y\) to \(x\). (Independent of order)

  2. Identity/Coincidence Axiom:

    • \(d(x, y) = 0 \iff x = y\)

    • If the points \(x\) and \(y\) are the same, the distance between them must be \(0\).

  3. Non-negativity Axiom:

    • \(d(x, y) \geqslant 0\)

    • The distance between any two points can never be negative.

  4. Triangle Inequality Axiom:

    • \(d(x, z) \leqslant d(x, y) + d(y, z)\)

    • The points \(x\), \(y\), and \(z\) can construct a triangle in n-dimensional space. Therefore, the length of any side (eg. \(d(x, z)\)) must be equal to or less than the sum of the lengths of the other two sides. (eg. \(d(x, z) \leqslant d(x, y) + d(y, z)\))

    • This is a natural property of both physical and metaphorical notions of distance: you can arrive at z from x by taking a detour through y, but this will not make your journey any faster than the shortest path. ("Metric space", 2023)

Where \(d(x, y)\) is the distance between the strings \(x\) and \(y\).

References

Wikipedia contributors. (2023-09-19). Metric space — Wikipedia, the free encyclopedia. Retrieved 2023-09-29, from https://en.wikipedia.org/wiki/Metric_space#Definition[archive.org]

Author

Thibault Debatty, solonovamax

Inheritors

Functions

Link copied to clipboard
abstract override fun distance(s1: String, s2: String): Double

Compute and return the metric distance.